<?php
Yii::app()->clientScript->registerScript('ajax-view', "
$('#orders-grid a.detail').live('click', function() {
           var oid = $(this).attr('name');
    $.ajax({
            type: 'POST',
            url: $(this).attr('href'),
            beforeSend: function(){ 
                $('#Order_'+oid).html('<img src=\"" . Yii::app()->theme->baseUrl . "/images/loading.gif\"/>').show(); 
            },
            success: function(html) {
                $('#Order_'+oid).html(html).show();
            },
            
        });
        return false;
});
    
");

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
    $('.search-form').toggle();
    return false;
});

$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('orders-grid', {
		data: $(this).serialize()
	});
	return false;
});
");

$this->title = 'Đơn đặt hàng';

echo CHtml::link('Tìm kiếm', '#', array('class' => 'search-button')); 
?>
<div class="search-form" style="display: none">
    <?php
    echo $this->renderPartial('_search_order', array(
        'model' => $model
    ));
    ?>
</div><!-- search-form -->
<?php
echo $this->renderFlash();
$pageSize = Yii::app()->user->getState('pageSize');
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'orders-grid',
    'dataProvider' => $model->search(),
    'cssFile' => Yii::app()->theme->baseUrl . '/css/gridview.css',
    'columns' => array(
        array(
            'name' => 'id',
            'htmlOptions' => array('width' => 30),
        ),
        array(
            'name' => 'account',
            'type' => 'html',
            'value' => 'OrderService::getAccount($data)',
            'htmlOptions' => array('align' => 'left', 'style' => 'width: 850px'),
        ),
        array(
            'class' => 'CButtonColumn',
//            'header' => 'Action',
            'template' => '',
            'deleteButtonImageUrl' => false,
            'htmlOptions' => array('width' => 60),
            'footer' => 'Items: ' . CHtml::dropDownList('pageSize', $pageSize, array(
                $pageSize => $pageSize,
                20 => 20,
                50 => 50,
                100 => 100), array(
                // change 'user-grid' to the actual id of your grid!!
                'onchange' => "$.fn.yiiGridView.update('order-grid',{ data:{pageSize: $(this).val() }})",
            )),
        ),
    ),
));
?>
